package androidx.appcompat.view.menu;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.appcompat.widget.AppCompatTextView;
import o.ah.g;
import o.bd.a;
import o.bj;
import o.bt;
import o.cm;
import o.cz;

@RestrictTo({d.LIBRARY_GROUP})
public class ActionMenuItemView extends AppCompatTextView implements o.bo.b, OnClickListener, androidx.appcompat.widget.ActionMenuView.b {
    private boolean ʻ;
    private int ʼ;
    private boolean ʽ;
    private CharSequence ˊ;
    b ˋ;
    a ˎ;
    bj ˏ;
    private int ˏॱ;
    private int ॱˊ;
    private Drawable ॱॱ;
    private cm ᐝ;

    public static abstract class b {
        public abstract bt ˏ();
    }

    class e extends cm {
        final /* synthetic */ ActionMenuItemView ॱ;

        public e(ActionMenuItemView actionMenuItemView) {
            this.ॱ = actionMenuItemView;
            super(actionMenuItemView);
        }

        public bt ˎ() {
            if (this.ॱ.ˋ != null) {
                return this.ॱ.ˋ.ˏ();
            }
            return null;
        }

        public boolean ˏ() {
            if (this.ॱ.ˎ == null || !this.ॱ.ˎ.ॱ(this.ॱ.ˏ)) {
                return false;
            }
            bt ˎ = ˎ();
            if (ˎ == null || !ˎ.ˎ()) {
                return false;
            }
            return true;
        }
    }

    public ActionMenuItemView(Context context) {
        this(context, null);
    }

    public ActionMenuItemView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public ActionMenuItemView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        Resources resources = context.getResources();
        this.ʽ = ॱॱ();
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, g.ʼॱ, i, 0);
        this.ʼ = obtainStyledAttributes.getDimensionPixelSize(g.ˈ, 0);
        obtainStyledAttributes.recycle();
        this.ˏॱ = (int) ((resources.getDisplayMetrics().density * 32.0f) + 0.5f);
        setOnClickListener(this);
        this.ॱˊ = -1;
        setSaveEnabled(false);
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        this.ʽ = ॱॱ();
        ʼ();
    }

    private boolean ॱॱ() {
        Configuration configuration = getContext().getResources().getConfiguration();
        int i = configuration.screenWidthDp;
        return i >= 480 || ((i >= 640 && configuration.screenHeightDp >= 480) || configuration.orientation == 2);
    }

    public void setPadding(int i, int i2, int i3, int i4) {
        this.ॱˊ = i;
        super.setPadding(i, i2, i3, i4);
    }

    public bj ˏ() {
        return this.ˏ;
    }

    public void ॱ(bj bjVar, int i) {
        this.ˏ = bjVar;
        setIcon(bjVar.getIcon());
        setTitle(bjVar.ˏ((o.bo.b) this));
        setId(bjVar.getItemId());
        setVisibility(bjVar.isVisible() ? 0 : 8);
        setEnabled(bjVar.isEnabled());
        if (bjVar.hasSubMenu() && this.ᐝ == null) {
            this.ᐝ = new e(this);
        }
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (this.ˏ.hasSubMenu() && this.ᐝ != null && this.ᐝ.onTouch(this, motionEvent)) {
            return true;
        }
        return super.onTouchEvent(motionEvent);
    }

    public void onClick(View view) {
        if (this.ˎ != null) {
            this.ˎ.ॱ(this.ˏ);
        }
    }

    public void setItemInvoker(a aVar) {
        this.ˎ = aVar;
    }

    public void setPopupCallback(b bVar) {
        this.ˋ = bVar;
    }

    public boolean a_() {
        return true;
    }

    public void setCheckable(boolean z) {
    }

    public void setChecked(boolean z) {
    }

    public void setExpandedFormat(boolean z) {
        if (this.ʻ != z) {
            this.ʻ = z;
            if (this.ˏ != null) {
                this.ˏ.ᐝ();
            }
        }
    }

    private void ʼ() {
        CharSequence charSequence;
        int i = 0;
        CharSequence charSequence2 = null;
        int i2 = !TextUtils.isEmpty(this.ˊ) ? 1 : 0;
        if (this.ॱॱ == null || (this.ˏ.ˋॱ() && (this.ʽ || this.ʻ))) {
            i = 1;
        }
        int i3 = i2 & i;
        if (i3 != 0) {
            charSequence = this.ˊ;
        } else {
            charSequence = null;
        }
        setText(charSequence);
        charSequence = this.ˏ.getContentDescription();
        if (TextUtils.isEmpty(charSequence)) {
            setContentDescription(i3 != 0 ? null : this.ˏ.getTitle());
        } else {
            setContentDescription(charSequence);
        }
        charSequence = this.ˏ.getTooltipText();
        if (TextUtils.isEmpty(charSequence)) {
            if (i3 == 0) {
                charSequence2 = this.ˏ.getTitle();
            }
            cz.ˋ(this, charSequence2);
            return;
        }
        cz.ˋ(this, charSequence);
    }

    public void setIcon(Drawable drawable) {
        this.ॱॱ = drawable;
        if (drawable != null) {
            float f;
            int intrinsicWidth = drawable.getIntrinsicWidth();
            int intrinsicHeight = drawable.getIntrinsicHeight();
            if (intrinsicWidth > this.ˏॱ) {
                f = ((float) this.ˏॱ) / ((float) intrinsicWidth);
                intrinsicWidth = this.ˏॱ;
                intrinsicHeight = (int) (((float) intrinsicHeight) * f);
            }
            if (intrinsicHeight > this.ˏॱ) {
                f = ((float) this.ˏॱ) / ((float) intrinsicHeight);
                intrinsicHeight = this.ˏॱ;
                intrinsicWidth = (int) (((float) intrinsicWidth) * f);
            }
            drawable.setBounds(0, 0, intrinsicWidth, intrinsicHeight);
        }
        setCompoundDrawables(drawable, null, null, null);
        ʼ();
    }

    public boolean ˋ() {
        return !TextUtils.isEmpty(getText());
    }

    public void setShortcut(boolean z, char c) {
    }

    public void setTitle(CharSequence charSequence) {
        this.ˊ = charSequence;
        ʼ();
    }

    public boolean c_() {
        return ˋ() && this.ˏ.getIcon() == null;
    }

    public boolean b_() {
        return ˋ();
    }

    public void onMeasure(int i, int i2) {
        boolean ˋ = ˋ();
        if (ˋ && this.ॱˊ >= 0) {
            super.setPadding(this.ॱˊ, getPaddingTop(), getPaddingRight(), getPaddingBottom());
        }
        super.onMeasure(i, i2);
        int mode = MeasureSpec.getMode(i);
        int size = MeasureSpec.getSize(i);
        int measuredWidth = getMeasuredWidth();
        size = mode == Integer.MIN_VALUE ? Math.min(size, this.ʼ) : this.ʼ;
        if (mode != 1073741824 && this.ʼ > 0 && measuredWidth < size) {
            super.onMeasure(MeasureSpec.makeMeasureSpec(size, 1073741824), i2);
        }
        if (!ˋ && this.ॱॱ != null) {
            super.setPadding((getMeasuredWidth() - this.ॱॱ.getBounds().width()) / 2, getPaddingTop(), getPaddingRight(), getPaddingBottom());
        }
    }

    public void onRestoreInstanceState(Parcelable parcelable) {
        super.onRestoreInstanceState(null);
    }
}
